<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>新增出库</title>
    <link rel="stylesheet" href="../../frame/layui/css/layui.css">
    <link rel="stylesheet" href="../../frame/static/css/style.css">
</head>
<body class="body">

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>新增出库</legend>
</fieldset>

<form class="layui-form" >

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">出库人</label>
            <div class="layui-input-inline">
                <select id="sta" name="staId" lay-verify="required">
                    <option value="1">哈哈哈</option>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">配件名称</label>
            <div class="layui-input-inline">
                <select id="rep" name="repId"  lay-verify="required">
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">出库数量</label>
        <div class="layui-input-inline">
            <input type="text" name="number" lay-verify="required|number" placeholder="请输入出库数量" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">必填</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">出库原因</label>
        <div class="layui-input-block">
            <textarea name="fetReason" placeholder="请输入内容(可选)" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">新增</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="../../js/jquery.js"></script>
<%--<script src="../../frame/layui/lay/modules/layer.js"></script>--%>
<script src="../../frame/layui/layui.js" charset="utf-8"></script>
<script>
    $(function () {
        loadStaName();
        loadRepName(1,0,null);
    });

    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,laydate = layui.laydate;

        form.on('submit(demo1)', function(data){
            add(data);
            return false;
        });

    });

    function loadRepName(pagenum,pagesize,keywords) {
        // layer.load(0);

        $("#rep").empty();
        $.ajax({
            url: "/stock/querystock",
            type: "POST",
            async:false,
            data: {
                keywords:keywords,
                pagenum:pagenum,
                pagesize:pagesize,
            },
            dataType: "json",
            success: function (data) {
                console.log(data);
                if(data.success){
                    var stocks = data.data.list;
                    for (var i = 0; i < stocks.length; i++) {
                        $("#rep").append(
                            "<option value='"+stocks[i].repid+"'>"+stocks[i].repname+"</option>"
                        );
                    }
                }else{
                    layer.msg(data.message);
                }
            }
        });
    }

    function loadStaName() {
        // layer.load(1);

        $("#sta").empty();
        $.ajax({
            url: "/Staff/selectAll",
            type: "POST",
            dataType: "json",
            success: function (data) {
                console.log(data);
                if(data.success){
                    var staffs = data.data;
                    for (var i = 0; i < staffs.length; i++) {
                        $("#sta").append(
                            "<option value='"+staffs[i].staid+"'>"+staffs[i].staname+"</option>"
                        );
                    }
                }else{
                    layer.msg(data.message);
                }
            }
        });
    }

    function add(data){

        var repId = data.field.repId;

        var staId = data.field.staId;

        var number = data.field.number;

        var fetreason = data.field.fetReason;

        $.ajax({
            url: "/stock/outstock/insertoutstock",
            type: "POST",
            dataType:"json",
            data: {
                repid:repId,
                staid:staId,
                number:number,
                fetreason:fetreason
            },
            success: function(data){
                if(data.success){
                    layer.confirm(data.message+"是否继续添加？", {
                        btn: ['继续', '取消'] //按钮
                    }, function(){
                        window.location.reload();
                    }, function(){
                        window.location.href="/stock/outstock/outstocklist.jsp";
                    });
                }else {
                    layer.msg("新增失败");
                }
            }
        });
    }
</script>
</body>
</html>
